<!DOCTYPE html>
<html lang="zh">

<head>

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>页面</title>
    <script src="https://pinzafile.oss-cn-shanghai.aliyuncs.com/vue-element/loading.js"></script>
    <link href="https://pinzafile.oss-cn-shanghai.aliyuncs.com/vue-element/lib/theme-chalk/index.css" rel="stylesheet">


</head>

<body>
<div id="app">
    <el-container>
        <el-header>
            <el-breadcrumb separator-class="el-icon-arrow-right">
                <el-breadcrumb-item :to="{ path: '/' }">合作商管理</el-breadcrumb-item>
                <el-breadcrumb-item>项目管理</el-breadcrumb-item>
            </el-breadcrumb>
        </el-header>
        <el-header>
            <el-row>
              <#list permissionList as bean>
                    <a href="${bean.permission_url}">
                        <el-col :xs="6" :sm="6" :md="4" :lg="2" :xl="2">
                            <el-button type="primary" icon="el-icon-edit"
                                       :offset="6">${bean.permission_name}</el-button>
                        </el-col>
                    </a>
              </#list>
                <el-col :xs="10" :sm="10" :md="8" :lg="8" :xl="8">
                    <el-input placeholder="请输入内容" @keyup.enter.native="enterSearch" v-model="keySearch">
                        <el-button slot="append" icon="el-icon-search" @click=search></el-button>
                    </el-input>
                </el-col>
            </el-row>
        </el-header>
        <el-main>
            <el-table :data="data.tableData" stripe border style="width:100%" highlight-current-row size="mini"
                      tooltip-effect="dark" height="calc(100vh - 240px)">
                <el-table-column label="序号" align="center" width="50px">
                    <template scope="scope"><span>{{scope.$index+(data.currentPage - 1) * data.pageSize + 1}}</span>
                    </template>
                    　　
                </el-table-column>
                　　
                <el-table-column prop="project_code" label="项目编号" align="center" :show-overflow-tooltip=true>
                    　　
                </el-table-column>
                　　
                <el-table-column prop="project_name" label="项目名称" align="center" :show-overflow-tooltip=true>
                    　　
                </el-table-column>
                <el-table-column prop="project_type" label="项目类型" align="center" :show-overflow-tooltip=true>
                    　　
                </el-table-column>
                　　
                <el-table-column prop="business_personnel" label="业务人员" align="center" :show-overflow-tooltip=true>
                    　　
                </el-table-column>
                　
                <el-table-column prop="project_area" label="项目区域" align="center" :show-overflow-tooltip=true>
                    　　
                </el-table-column>
                <el-table-column prop="project_stage" label="项目阶段" align="center" :show-overflow-tooltip=true>
                    　　
                </el-table-column>
                　　
                <el-table-column label="操作" align="center" min-width="140" fixed="right">
                    　　　　
                    <template slot-scope="scope">
                        　　　　　
                        <template v-for="item in button">
                            <el-button type="text" @click="item.fn(scope.row.id)">{{item.name}}</el-button>
                        </template>
                        　　　　
                    </template>
                    　　
                </el-table-column>
            </el-table>
        </el-main>
        <el-footer>
            <el-row>
                <el-col>
                    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                                   :page-sizes="[100, 500, 1000]" :page-size="data.pageSize"
                                   layout="total, sizes, prev, pager, next, jumper"
                                   :total="data.totalRecords">
                    </el-pagination>
                </el-col>
            </el-row>
        </el-footer>
    </el-container>
</div>

<script src="https://pinzafile.oss-cn-shanghai.aliyuncs.com/vue-element/dist/vue.js"></script>
<script src="https://pinzafile.oss-cn-shanghai.aliyuncs.com/vue-element/lib/index.js"></script>
<script src="https://pinzafile.oss-cn-shanghai.aliyuncs.com/publiccss/assets/global/plugins/jquery.min.js"
        type="text/javascript"></script>
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                company_id:'${company_id}',
                data: {
                    tableData: [],
                    currentPage: 1, //当前页
                    pageSize: 100, //每页总数
                    totalRecords: 0, //总条数
                },
                keySearch: '',
                //后台权限列表拼接
                button: [],
            };
            show:false

        },

        methods: {
            //回车监听事件获取输入内容
            enterSearch(event) {
                this.data.currentPage=1;
                this.data.pageSize=100;
                this.keySearch = event.target.value;
                this.ajaxFunction();
            },
            //点击事件获取输入内容
            search() {
                this.data.currentPage=1;
                this.data.pageSize=100;
                this.ajaxFunction();
            },
            ajaxFunction() {
                $.ajax({
                    url: '/project/list.json',
                    type: 'post',
                    data: {key: this.keySearch, page: this.data.currentPage, limit: this.data.pageSize},
                    dataType: 'json',
                    success: (result) => {
                        console.log(result.data)
                        if (result.ret) {
                            this.data.tableData = result.data.list;
                            this.data.totalRecords = result.data.count;
                            this.button = result.data.operaButton;
                            var tempVue = this;
                            this.button.forEach(function (ele) {
                                ele.fn = tempVue[ele.fn]
                            })
                        }else{

                        }
                    }
                });
            },
            //作废
            del(id) {
                this.$confirm('此操作将永久作废该企业, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                    center: true
                }).then(() => {
                    var bool = false;
                    var err = "";
                    $.ajax({
                        url: '/company/cancel.json',
                        type: 'post',
                        data: {id: id},
                        async: false,
                        dataType: 'json',
                        success: function (result) {
                            if (result.ret) {
                                bool = result.ret;
                            } else {
                                err = result.msg;
                            }
                        }
                    });
                    if (bool) {
                        this.$message({
                            type: 'success',
                            message: '作废成功'
                        });
                        this.ajaxFunction()
                    } else {
                        this.$message({
                            type: 'success',
                            message: err
                        });
                    }

                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消操作'
                    });

                });
            },
            //修改用户
            modify(val) {
                if(this.company_id === '1'){
                    this.$message.error('甲方不可编辑渠道商项目信息哦！');
                }else{
                    window.location.href = "/project/update.page?id=" + val;
                }
            },
            //查看详情
            detail(val) {
                window.location.href = "/project/detail.page?id=" + val;
            },
            async handleSizeChange(val) {
                this.data.pageSize = val;
                this.ajaxFunction();

            },
            //
            async handleCurrentChange(val) {
                this.data.currentPage = val;
                this.ajaxFunction();

            },


        },

        async mounted() {
            this.ajaxFunction();
        }
    })
</script>
</body>

</html>